<?php

/**
 * MVM_MALL 网上商店系统 商品评论管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-07-14 $
 * $Id: comment.inc.php  www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if($action=='list'){
    require_once MVMMALL_ROOT.'./include/pager.class.php';
    $total_count = $db->counter("{$tablepre}gcomment_table");
    $page        = $page ? (int)$page:1;
    $list_num    = 10;
    $rowset      = new Pager($total_count,$list_num,$page);
    $from_record = $rowset->_offset();
    $result      = $db->query("SELECT a.*,b.uid AS goods_id,b.goods_name FROM `{$tablepre}gcomment_table` a LEFT JOIN `{$tablepre}goods_table` b ON a.guid = b.uid ORDER BY `uid` DESC LIMIT $from_record, $list_num");
    while ($rt   = $db->fetch_array($result)) {
        $rt['goods_name']         = cut_str($rt['goods_name'],20);
        $rt['comment_subject']    = cut_str($rt['comment_subject'],22);
        $rt['register_date']      = date($mm_date_format,$rt['register_date']);
        $rt['app']                = $rt['approval_date']>0 ? $lang['approval_yes']:$lang['approval_no'];
        $rt['url']                = "comment.php?action=view&id=$rt[goods_id]";
        $rt['edit']               = "admincp.php?module=$module&action=edit&uid=$rt[uid]&per=ajax";
        $rt['del']                = "admincp.php?module=$module&action=del&uid=$rt[uid]&per=ajax";
        $rt['logo']               && $rt['logo']= "<img src=\"$rt[logo]\" border=\"0\"/>";
        $comment_rt[]             = $rt;
    }
    $page_list = $rowset->link("admincp.php?module=$module&action=$action&page=");
    require_once template('comment');
    footer();
} elseif ($action == 'edit' && is_numeric($uid)) {//通过审核
    unset($app);
    $rt = $db->get_one("SELECT approval_date,uid FROM `{$tablepre}gcomment_table` WHERE uid='$uid'");
    $rt['approval_date'] >0 ? $app = 0 : $app= $m_now_time;
    $db->query("UPDATE `{$tablepre}gcomment_table` SET approval_date = '$app' WHERE uid='$uid'");;
    if ($per=='ajax') {
    	echo $rt['approval_date']>0 ? $lang['approval_no'] :$lang['approval_yes'];
    }else {
        admin_msg('success',dreferer());
    }
} elseif ($action=='del'){
    if (is_array($uid_check)) {
        for($i=0;$i<count($uid_check);$i++) {
            $uid = (int)$uid_check[$i];
            $db->query("DELETE FROM `{$tablepre}gcomment_table` WHERE uid='$uid'");
            $db->query("DELETE FROM `{$tablepre}reply_comment` WHERE com_id='$uid'");
        }
    } elseif (is_numeric($uid)){
        $db->query("DELETE FROM `{$tablepre}gcomment_table` WHERE uid='$uid'");
        $db->query("DELETE FROM `{$tablepre}reply_comment` WHERE com_id='$uid'");
    }else {
        admin_msg('pass_worng');
    }
    $per!='ajax' && admin_msg('success',dreferer());
}  else {
    admin_msg('pass_worng');
}